package keeto.com.vn.bms.network.task;

import java.io.IOException;

import org.apache.http.client.ClientProtocolException;
import org.json.JSONException;

import keeto.com.vn.bms.config.IBMSConfig;
import keeto.com.vn.bms.config.IBMSCore;
import keeto.com.vn.bms.network.request.GetDetailReportFileRequest;
import keeto.com.vn.bms.network.response.GetDetailReportFileResponse;
import keeto.com.vn.bms.utils.BMSListener;

public class TaskGetDetailReportFile extends AbstractTask{
	private int type;
	private String CompanyId;
	private String CaseId;
	private String DateStart;
	private String DateEnd;
	private String AuthKey;
	
	public TaskGetDetailReportFile(BMSListener listener, IBMSCore core,
			int type, String companyId, String caseId, String dateStart,
			String dateEnd, String authKey) {
		super(listener, core);
		this.type = type;
		CompanyId = companyId;
		CaseId = caseId;
		DateStart = dateStart;
		DateEnd = dateEnd;
		AuthKey = authKey;
	}
	@Override
	public void run() throws ClientProtocolException, JSONException,
			IOException {
		// TODO Auto-generated method stub
		GetDetailReportFileRequest request = new GetDetailReportFileRequest();
		request.setType(type);
		request.setCaseId(CaseId);
		request.setCompanyId(CompanyId);
		request.setDateStart(DateStart);
		request.setDateEnd(DateEnd);
		request.setAuthKey(AuthKey);
		GetDetailReportFileResponse response = protocol.getDetailReportFile(request);
		for(BMSListener mlistener:listener){
			mlistener.finishGetDetailReportFile(response.getReturnCode(), response.getResultMsg(),request.getType(), response.getLink());
		}
		
	}
	@Override
	public void timeoutCallback() {
		// TODO Auto-generated method stub
		for(BMSListener mlistener:listener){
			mlistener.finishGetDetailReportFile(protocol.STATUS_CODE_GENERIC_FAIL_CONECTTION, null,IBMSConfig.UNINITIALIZED_INT, null);
		}
	}
	
}
